/**
 *  GeneralPg.cpp
 *
 *  Copyright (C) 2008  David Andrs <pda@jasnapaka.com>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include "stdafx.h"
#include "mcountdown.h"
#include "GeneralPg.h"
#include "..\share\config.h"

#include "ctrls\CePropertySheet.h"
#include "AboutPg.h"
#include "LicensePg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CGeneralPg property page

IMPLEMENT_DYNCREATE(CGeneralPg, CPropertyPage)

CGeneralPg::CGeneralPg() : CPropertyPage(CGeneralPg::IDD)
{
	//{{AFX_DATA_INIT(CGeneralPg)
	m_strName = Config.EventName;
	m_nDay = Config.Event.wDay;
	m_nMonth = Config.Event.wMonth;
	m_nYear = Config.Event.wYear;
	//}}AFX_DATA_INIT
}

CGeneralPg::~CGeneralPg()
{
}

void CGeneralPg::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CGeneralPg)
	DDX_Control(pDX, IDC_NAME, m_ctlName);
	DDX_Control(pDX, IDC_DAY, m_ctlDay);
	DDX_Control(pDX, IDC_DAY_SPIN, m_ctlDaySpin);
	DDX_Control(pDX, IDC_MONTH, m_ctlMonth);
	DDX_Control(pDX, IDC_MONTH_SPIN, m_ctlMonthSpin);
	DDX_Control(pDX, IDC_YEAR, m_ctlYear);
	DDX_Control(pDX, IDC_YEAR_SPIN, m_ctlYearSpin);
	DDX_Control(pDX, IDC_EVENT_LBL, m_lblEvent);
	DDX_Text(pDX, IDC_NAME, m_strName);
	DDX_Text(pDX, IDC_DAY, m_nDay);
	DDX_Text(pDX, IDC_MONTH, m_nMonth);
	DDX_Text(pDX, IDC_YEAR, m_nYear);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CGeneralPg, CPropertyPage)
	//{{AFX_MSG_MAP(CGeneralPg)
	ON_COMMAND(ID_ABOUT, OnAbout)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGeneralPg message handlers

BOOL CGeneralPg::OnInitDialog() {
	CPropertyPage::OnInitDialog();

	m_ctlDaySpin.SendMessage(CCM_SETVERSION, COMCTL32_VERSION);
	m_ctlDaySpin.SetRange(1, 31);

	m_ctlMonthSpin.SendMessage(CCM_SETVERSION, COMCTL32_VERSION);
	m_ctlMonthSpin.SetRange(1, 12);

	m_ctlYearSpin.SendMessage(CCM_SETVERSION, COMCTL32_VERSION);
	m_ctlYearSpin.SetRange(1, 9999);

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CGeneralPg::OnOK() {
	Config.EventName = m_strName;
	Config.Event.wDay = m_nDay;
	Config.Event.wMonth = m_nMonth;
	Config.Event.wYear = m_nYear;

	CPropertyPage::OnOK();
}

void CGeneralPg::UpdateControls() {

}

void CGeneralPg::OnAbout() {
	CAboutPg pgAbout;
	CLicensePg pgLicense;

	CCePropertySheet sheet(IDS_ABOUT);
	
	sheet.AddPage(&pgAbout);
	sheet.AddPage(&pgLicense);

	sheet.SetMenu(IDR_CANCEL);
	sheet.DoModal();
}
